<?php
    if ($db = new SQLiteDatabase('logger.db')) {
		$event = sqlite_escape_string($_REQUEST['event']);
	
		$prepared = "SELECT * FROM events WHERE event = '%s'";
		$query = sprintf($prepared, $event);
		$data = $db->query($query);
		$counts = array();
		while($data->valid()) {
			$current = $data->current();
			$condition = $current['condition'];
			if (!isset($counts[$condition])) {
				$counts[$condition] = 1;
			} else {
				$counts[$condition]++;
			}
			$data->next();
		}
		$series = array();
		$i = 0;
		foreach ($counts as $key => $value) {
			array_push($series, array(
				"label"=>$key,
				"data"=>array(array($i, $value))
			));
			$i++;
		}
		echo json_encode($series);
	}

?>